const url = 'http://172.21.63.114:10001'

export function request(opt){
    uni.showLoading({
		title:'加载中'
	});
    return new Promise((resolve,reject)=>{
        uni.request({
            url:url+opt.url,
            method:opt.method,
			data:opt.data ? opt.data : '',
            header:{
                'Authorization':opt.url=='/prod-api/api/login' || opt.url == '/prod-api/api/register' ? "" : uni.getStorageSync('token'),
            },
            success:(res)=>{
				uni.hideLoading();
                if(opt.url=='/prod-api/api/login'){
                    uni.setStorage({
                        key: 'token',
                        data: res.data.token,
                        success: function () {
                            console.log('success');
                        }
                    });
                    resolve(res)
                }else{
                    resolve(res)
                }
            },
            fail:(err)=>{
				uni.hideLoading();
                reject(err)
            }
        })
    })

}